﻿using System;
using System.Linq;
using BO.News;
using GUI.Extensions;
using System.Text;
using Utilities.Entities;
using BugManager;

namespace GUI.Controls.News
{
    public partial class SubCategories : System.Web.UI.UserControl
    {
        private const string LiFormat = "<li><a href=\"{0}\" title=\"{1}\">{1}</a></li>";
        private const string BreadcrumbFormat = "<div itemscope itemtype=\"http://data-vocabulary.org/Breadcrumb\"><a href=\"{0}\" itemprop=\"url\"><span itemprop=\"title\">{1}</span></a>{2}</div>";
        private const string Seperator = " › ";
        protected void Page_Load(object sender, EventArgs e)
        {
            Visible = false;
            return;
            try
            {
                var objCategory = RequestExtensions.Category;
                if (objCategory != null)
                {
                    var breadcrumb = new StringBuilder();
                    breadcrumb.AppendFormat(BreadcrumbFormat, "/", "soha.vn", Seperator);

                    var allCategories = NewsBO.GetInstance().GetAllCategories();
                    if (allCategories != null && allCategories.Any())
                    {
                        var query =
                            from c in allCategories
                            let parentId = objCategory.ParentId > 0 ? objCategory.ParentId : objCategory.Id
                            where c.Id == parentId || c.ParentId == parentId
                            orderby c.ParentId, c.SortOrder
                            select c;
                        var categoryObjects = query as CategoryObject[] ?? query.ToArray();
                        if (categoryObjects.Any())
                        {

                            var sb = new StringBuilder();
                            foreach (var c in categoryObjects)
                            {
                                sb.AppendFormat(
                                            LiFormat,
                                            c.Url,
                                            c.Name
                                        );
                                if (objCategory.ParentId > 0 && objCategory.ParentId == c.Id)
                                    breadcrumb.AppendFormat(BreadcrumbFormat, c.Url, c.Name.ToLower(), string.Empty);

                            }
                            ltrSubMenu.Text = sb.ToString();
                            if (objCategory.ParentId == 0)
                            {
                                breadcrumb.AppendFormat(BreadcrumbFormat, objCategory.Url, objCategory.Name.ToLower(), string.Empty);
                            }
                            ltrBreadcrumb.Text = breadcrumb.ToString();
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorManager.Log(ex.ToString());
            }
            Visible = false;
        }
    }
}
